﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="menetlusinfo_dokument", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MenetlusinfoDokument))]
    public class MenetlusinfoDokumentSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMenetlusinfoDokument clazz;
        
        public MenetlusinfoDokumentSerializer(IMenetlusinfoDokument clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("paevikukande_id");
            if (clazz.PaevikukandeId!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PaevikukandeId))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PaevikukandeId");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("esit_kp");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.EsitKp))).ToString());
            Writer.WriteEndElement();
            if (clazz.DokLiik!=null) {
                Writer.WriteStartElement("dok_liik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokLiik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.DokOlek!=null) {
                Writer.WriteStartElement("dok_olek");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_dok_olek");
                Writer.WriteString(clazz.DokOlek.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Notarnr!=null) {
                Writer.WriteStartElement("notarnr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Notarnr))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("notar_id");
            if (clazz.NotarId!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.NotarId))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : NotarId");
            }
            Writer.WriteEndElement();
            if (clazz.EttevotjaRegKood!=null) {
                Writer.WriteStartElement("ettevotja_reg_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EttevotjaRegKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EttevotjaNimi!=null) {
                Writer.WriteStartElement("ettevotja_nimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EttevotjaNimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Hoiatus!=null) {
                Writer.WriteStartElement("hoiatus");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("menetlusinfo_hoiatus", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Hoiatus.Count);
                if (((clazz.Hoiatus == null) 
                            || (clazz.Hoiatus.Count < 1m))) {
                    throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                }
                for (int x = 0; ((clazz.Hoiatus != null) 
                            && (x < clazz.Hoiatus.Count)); x = (x + 1)) {
                    Writer.WriteStartElement("item");
                    if (clazz.Hoiatus[x]!=null) {
                        global::Xtee.Core.SerializationMetadata metaHoiatus = this.GetMetaData(clazz.Hoiatus[x]);
                        Writer.WriteTypeAttribute(metaHoiatus.TypeQualifiedName.Namespace, metaHoiatus.TypeQualifiedName.Name);
                        metaHoiatus.NewSerializer(clazz.Hoiatus[x]).WriteXml(Writer);
                    }
                    else {
                        Writer.WriteAttributeString("xsi", "nil", null, "1");
                    }
                    Writer.WriteEndElement();
                }
                Writer.WriteEndElement();
            }
            if (clazz.Maarus!=null) {
                Writer.WriteStartElement("maarus");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("menetlusinfo_maarus", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Maarus.Count);
                if (((clazz.Maarus == null) 
                            || (clazz.Maarus.Count < 1m))) {
                    throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                }
                for (int x = 0; ((clazz.Maarus != null) 
                            && (x < clazz.Maarus.Count)); x = (x + 1)) {
                    Writer.WriteStartElement("item");
                    if (clazz.Maarus[x]!=null) {
                        global::Xtee.Core.SerializationMetadata metaMaarus = this.GetMetaData(clazz.Maarus[x]);
                        Writer.WriteTypeAttribute(metaMaarus.TypeQualifiedName.Namespace, metaMaarus.TypeQualifiedName.Name);
                        metaMaarus.NewSerializer(clazz.Maarus[x]).WriteXml(Writer);
                    }
                    else {
                        Writer.WriteAttributeString("xsi", "nil", null, "1");
                    }
                    Writer.WriteEndElement();
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="paevikukande_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>menetlusinfo_dokument>paevikukande_id");
                }
                clazz.PaevikukandeId = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("paevikukande_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>menetlusinfo_dokument>paevikukande_id", Reader.LocalName);
            }
            if (Reader.LocalName=="esit_kp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>menetlusinfo_dokument>esit_kp");
                }
                clazz.EsitKp = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("esit_kp")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>menetlusinfo_dokument>esit_kp", Reader.LocalName);
            }
            if (Reader.LocalName=="dok_liik") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.DokLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("dok_liik")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="dok_olek") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.DokOlek = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XDokOlek(Reader.ReadElementString("dok_olek"));
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="notarnr") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Notarnr = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("notarnr")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="notar_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>menetlusinfo_dokument>notar_id");
                }
                clazz.NotarId = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("notar_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>menetlusinfo_dokument>notar_id", Reader.LocalName);
            }
            if (Reader.LocalName=="ettevotja_reg_kood") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.EttevotjaRegKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ettevotja_reg_kood")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ettevotja_nimi") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.EttevotjaNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ettevotja_nimi")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="hoiatus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Hoiatus = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoHoiatus>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("hoiatus");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.LocalName=="item") {
                                if ((Reader.IsElementNil() == false)) {
                                    global::Xtee.Core.SerializationMetadata metaHoiatus = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoHoiatus>(Reader, "menetlusinfo_hoiatus", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                                    global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoHoiatus item = metaHoiatus.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoHoiatus>();
                                    clazz.Hoiatus.Add(item);
                                    if ((Reader.IsEmptyElement == false)) {
                                        Reader.ReadStartElement("item");
                                        metaHoiatus.NewSerializer(item).ReadXml(Reader);
                                        Reader.ReadEndElement();
                                    }
                                    else {
                                        Reader.Skip();
                                    }
                                }
                                else {
                                    clazz.Hoiatus.Add(null);
                                    Reader.Skip();
                                }
                            }
                            else {
                                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">item", Reader.LocalName);
                            }
                        }
                        if ((clazz.Hoiatus.Count < 1m)) {
                            throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="maarus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Maarus = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoMaarus>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("maarus");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.LocalName=="item") {
                                if ((Reader.IsElementNil() == false)) {
                                    global::Xtee.Core.SerializationMetadata metaMaarus = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoMaarus>(Reader, "menetlusinfo_maarus", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                                    global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoMaarus item = metaMaarus.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoMaarus>();
                                    clazz.Maarus.Add(item);
                                    if ((Reader.IsEmptyElement == false)) {
                                        Reader.ReadStartElement("item");
                                        metaMaarus.NewSerializer(item).ReadXml(Reader);
                                        Reader.ReadEndElement();
                                    }
                                    else {
                                        Reader.Skip();
                                    }
                                }
                                else {
                                    clazz.Maarus.Add(null);
                                    Reader.Skip();
                                }
                            }
                            else {
                                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">item", Reader.LocalName);
                            }
                        }
                        if ((clazz.Maarus.Count < 1m)) {
                            throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
